/**
 * @author zyj
 * @date 2022年06月09日 9:51
 */
public class NofityDemo {
    public static void main(String[] args) {
        Object obj = new Object();
        Thread download = new Thread() {
            @Override
            public void run() {
                System.out.println("开始下载图片");
                for (int i = 0; i <= 100; i += 10) {
                    System.out.println("图片下载了" + i + "%");
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("图片下载完成");
//                synchronized (obj){
//                    obj.notifyAll();
//                }
                System.out.println("开始下载附件");
                for (int i = 0; i <= 100; i += 10) {
                    System.out.println("附件下载了" + i + "%");
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("附件下载完成");
            }
        };


        Thread show = new Thread(){
            @Override
            public void run() {
                synchronized (obj){

                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("图片已经下载完成，图片显示成功");
            }
        };
        download.start();
        show.start();
    }
}
